package org.example.Controller;

import org.example.service.impl.RedisMessageQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageController {

    @Autowired
    private RedisMessageQueue redisMessageQueue;

    @RequestMapping("/send")
    public String sendMessage(@RequestParam(value = "message") String message) {
        String queueName = "message-queue";
        redisMessageQueue.sendMessage(queueName, message);
        return "Message sent: " + message;
    }

    @RequestMapping("/receive")
    public Object receiveMessage() {
        String queueName = "message-queue";
        Object message = redisMessageQueue.receiveMessage(queueName);
        return "Message received: " + message;
    }


    @RequestMapping("/publishMessage")
    public void publishMessage(String channel, String message) {
        redisMessageQueue.convertAndSend(channel, message);
    }


    /**
     * https://juejin.cn/post/7239881176680366139
     */


}